home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / nrhdr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  2.5 KB  |  136 lines

  1. /* Functions for level 3 net/rom support */
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "ax25.h"
  5. #include "netrom.h"
  6. #include "lapb.h"
  7. #include <ctype.h>
  8.  
  9. /* Convert a net/rom network header to host format structure
  10.  * Return -1 if error, 0 if OK
  11.  */
  12.  
  13. int
  14. ntohnr3(hdr,bpp)
  15. register struct nr3hdr *hdr ;    /* output structure */
  16. struct mbuf **bpp ;
  17. {
  18.     char ttl ;
  19.     
  20.     if (pullup(bpp,hdr->source,AXALEN) < AXALEN)
  21.         return -1 ;
  22.  
  23.     if (pullup(bpp,hdr->dest,AXALEN) < AXALEN)
  24.         return -1 ;
  25.  
  26.     if (pullup(bpp,&ttl,1) != 1)
  27.         return -1 ;
  28.  
  29.     hdr->ttl = uchar(ttl) ;
  30.  
  31.     return 0 ;
  32. }
  33.  
  34. /* Convert a host-format net/rom level 3 header into an mbuf ready
  35.  * for transmission.
  36.  */
  37.  
  38. struct mbuf *
  39. htonnr3(hdr)
  40. register struct nr3hdr *hdr;
  41. {
  42.     struct mbuf *rbuf ;
  43.     register char *cp ;
  44.  
  45.     if (hdr == (struct nr3hdr *) NULL)
  46.         return NULLBUF ;
  47.  
  48.     /* Allocate space for return buffer */
  49.     if ((rbuf = alloc_mbuf(NR3HLEN)) == NULLBUF)
  50.         return NULLBUF ;
  51.  
  52.     rbuf->cnt = NR3HLEN ;
  53.  
  54.     /* Now convert */
  55.     cp = rbuf->data ;
  56.  
  57.     memcpy(cp,hdr->source,AXALEN);
  58.     cp[ALEN] &= ~E ;    /* source E-bit is always off */
  59.     cp += AXALEN;
  60.     memcpy(cp,hdr->dest,AXALEN);
  61.     cp[ALEN] |= E ;        /* destination E-bit always set */
  62.     cp += AXALEN;
  63.     *cp = hdr->ttl ;
  64.  
  65.     return rbuf ;
  66. }
  67.  
  68. /* Convert a net/rom routing broadcast destination subpacket from
  69.  * network format to a host format structure.  Return -1 if error,
  70.  * 0 if OK.
  71.  */
  72. int
  73. ntohnrdest(ds,bpp)
  74. register struct nr3dest *ds ;
  75. struct mbuf **bpp ;
  76. {
  77.     char quality ;
  78.  
  79.     /* get destination callsign */
  80.     if (pullup(bpp,ds->dest,AXALEN) < AXALEN)
  81.         return -1 ;
  82.  
  83.     /* get destination alias */
  84.     if (pullup(bpp,ds->alias,ALEN) < ALEN)
  85.         return -1 ;
  86.     ds->alias[ALEN] = '\0' ;
  87.  
  88.     /* get best neighbor callsign */
  89.     if (pullup(bpp,ds->neighbor,AXALEN) < AXALEN)
  90.         return -1 ;
  91.  
  92.     /* get route quality */
  93.     if (pullup(bpp,&quality,1) < 1)
  94.         return -1 ;
  95.     ds->quality = uchar(quality) ;
  96.  
  97.     return 0 ;
  98. }
  99.  
  100. /* Convert a host-format net/rom destination subpacket into an
  101.  * mbuf ready for transmission as part of a route broadcast
  102.  * packet.
  103.  */
  104. struct mbuf *
  105. htonnrdest(ds)
  106. register struct nr3dest *ds ;
  107. {
  108.     struct mbuf *rbuf ;
  109.     register char *cp ;
  110.  
  111.     if (ds == (struct nr3dest *) NULL)
  112.         return NULLBUF ;
  113.  
  114.     /* Allocate space for return buffer */
  115.     if ((rbuf = alloc_mbuf(NRRTDESTLEN)) == NULLBUF)
  116.         return NULLBUF ;
  117.  
  118.     rbuf->cnt = NRRTDESTLEN ;
  119.  
  120.     cp = rbuf->data ;
  121.  
  122.     memcpy(cp,ds->dest,AXALEN) ;
  123.     cp += AXALEN;
  124.  
  125.     memcpy(cp,ds->alias,ALEN) ;
  126.     cp += ALEN ;
  127.  
  128.     memcpy(cp,ds->neighbor,AXALEN) ;
  129.     cp += AXALEN;
  130.  
  131.     *cp = uchar(ds->quality) ;
  132.  
  133.     return rbuf ;
  134. }
  135.  
  136.